package com.feihong.txgw.ui.activity.kaika;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import android.webkit.JavascriptInterface;
import android.widget.Toast;

import com.just.agentweb.AgentWeb;


/**
 * Created by Sabirjan on 2017/7/6.
 * TXGWApp.
 * 飞宏电子
 */

class Step3Interface {

    private AgentWeb agent;
    private Context context;
    private String iccid = "";
    private String phonenum = "";

    public Step3Interface(AgentWeb agent, Context context, String iccid, String phonenum) {
        this.agent = agent;
        this.context = context;
        this.iccid = iccid;
        this.phonenum = phonenum;
    }

    private Handler deliver = new Handler(Looper.getMainLooper());

    @JavascriptInterface
    public void callAndroid(final String msg) {

        deliver.post(new Runnable() {
            @Override
            public void run() {
                if(TextUtils.isEmpty(iccid)){
                    Toast.makeText(context,"iccid不能为空",Toast.LENGTH_SHORT).show();
                    return;
                }else if(TextUtils.isEmpty(phonenum)){
                    Toast.makeText(context,"手机号码不能为空",Toast.LENGTH_SHORT).show();
                    return;
                }else if(TextUtils.isEmpty(msg)){
                    Toast.makeText(context,"服务端返回数据有误",Toast.LENGTH_SHORT).show();
                    return;
                }else {
                    Intent intent = new Intent();
                    intent.setClass(context, KaiKaStep4Activity.class);
                    intent.putExtra(KaiKaActivity.INTENT_ICCID, iccid);
                    intent.putExtra(KaiKaActivity.INTENT_PHOE_NUM, phonenum);
                    intent.putExtra("json", msg);
                    context.startActivity(intent);
                }
            }
        });

        //对外接口
    }

}
